//
//  WYRTabBarViewController.m
//  10-21-快速搭建框架
//
//  Created by lkx0 on 16/10/21.
//  Copyright © 2016年 lkx0. All rights reserved.
//

#import "WYRTabBarViewController.h"
#import "WYRNavigationController.h"
#import "WYROneViewController.h"
#import "WYRTwoViewController.h"
#import "WYRThreeViewController.h"
#import "WYRFourViewController.h"
@interface WYRTabBarViewController ()

@end

@implementation WYRTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //加载所有的视图控制器，
    [self setUpAllControllers];
   }

//设置所有的控制界面
-(void)setUpAllControllers{
    //1.添加第一个界面控制器
    //1.1初始化界面
//    WYROneViewController * one = [[WYROneViewController alloc]init];
//    //添加
//    [self setUpOneChildViewController:one andImgName:@"1"  andTitle:@"欢迎使用风云APP"];
   
    WYRTwoViewController * two=[[WYRTwoViewController alloc]init];
    [self setUpOneChildViewController:two andImgName:@"2" andTitle:@"动态"];
    
    WYRThreeViewController * three=[[WYRThreeViewController alloc]init];
    [self setUpOneChildViewController:three andImgName:@"3" andTitle:@"应用"];
    WYRFourViewController * four=[[WYRFourViewController alloc]init];
    [self setUpOneChildViewController:four andImgName:@"4" andTitle:@"钱包"];

}

//添加第二个控制器
//设置一个控制器的封装方法
-(void)setUpOneChildViewController:(UIViewController *)viewController andImgName:(NSString *)imgName  andTitle:(NSString *)title{
    //1.2将one设置为navigationController的根控制器
    WYRNavigationController * nav = [[WYRNavigationController alloc]initWithRootViewController:viewController];
    
    nav.title=title;
    viewController.navigationItem.title=title;
    //修改图片的默认渲染
    [self setImgageForBarItem:imgName andNavC:nav];
    
    // 默认将标题文字渲染成蓝色改成我们想要的颜色
    [self modifiItemTextColor:[UIColor redColor] andNavC:nav];
    
    //1.3将导航栏控制器Nav1交给tabbar管理
    [self addChildViewController:nav];

}

 // 取消默认的图片渲染
-(void)setImgageForBarItem:(NSString *)imgName andNavC:(WYRNavigationController *)nav{
    //修改图片的默认渲染
    UIImage * img=[UIImage imageNamed:imgName];
    img=[img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //将不会渲染的原始图片设置给tabbar
    nav.tabBarItem.image=img;
    

}

 //tabbar的item文字修改颜色
-(void)modifiItemTextColor:(UIColor *)color andNavC:(WYRNavigationController *)nav{
    //默认将标题文字渲染成蓝色改成我们想要的颜色
    NSMutableDictionary * dict=[NSMutableDictionary dictionary];
    [dict setObject:color forKey:NSForegroundColorAttributeName];
    [nav.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
